package com.hc.music.controller;

import com.hc.music.common.R;
import com.hc.music.entity.Level;
import com.hc.music.service.LevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("level")
public class LevelController {
    @Autowired
    private LevelService levelService;

    @RequestMapping("insert")
    public R insertLevel(@RequestBody Level level){
        return levelService.insertLevel(level);
    }

    @RequestMapping("selectAvgBySongListId")
    public R selectAvgBySongListId(@RequestParam Integer songListId){
        return levelService.selectSumAvg(songListId);
    }

    @RequestMapping("selectScore")
    public R selectScoreById(@RequestParam Integer userId, @RequestParam Integer songListId){
        System.out.println("nowUserId:" + userId +"songListId:"+songListId);
        R r = levelService.selectUserLevel(userId, songListId);
        System.out.println(r.getCode()+ "---" + r.getData());
        return r;
    }
}
